package com.eling.elcms.travel.service.impl;

import com.eling.elcms.core.exception.BusinessException;
import com.eling.elcms.core.service.impl.GenericManagerImpl;
import com.eling.elcms.travel.dao.IAllianceOrgDao;
import com.eling.elcms.travel.model.AllianceOrg;
import com.eling.elcms.travel.service.IAllianceOrgManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AllianceOrgManagerImpl extends GenericManagerImpl<AllianceOrg, Long> implements IAllianceOrgManager{

	IAllianceOrgDao allianceOrgDao;

	@Autowired
	public void setAllianceOrgDao(IAllianceOrgDao allianceOrgDao) {
		this.dao = allianceOrgDao;
		this.allianceOrgDao = allianceOrgDao;
	}

	@Override
	public AllianceOrg saveorg(AllianceOrg allianceOrg) {
		//名称唯一性判断
		AllianceOrg all = new AllianceOrg();
		List<AllianceOrg> list = this.query(all);
		for (AllianceOrg alliance : list) {
			if(alliance.getName().equals(allianceOrg.getName())){
				if(!alliance.getPkAllianceOrg().equals(allianceOrg.getPkAllianceOrg())){
					throw new BusinessException("名称不能重复");
				}
			}
		}
		return this.save(allianceOrg);
	}
}
